<?php
session_start();
if(isset($_SESSION['admin_id'])) {
    include ("../include/menu.php");
    include('../include/dbFunctions.php');
    $admin_id=$_SESSION['admin_id'];
    /* Query school details from database */
    $query1 = "SELECT * FROM quanly WHERE admin_id=$admin_id";
    $result1 = executeSelectQuery($query1);
    if (isset($_SESSION['mes'])) {
        $mes=$_SESSION['mes'];
        $_SESSION['mes']="";
    }

    $admin_name = $result1[0]['admin_name'];
    $admin_email = $result1[0]['admin_email'];
    $admin_password = $result1[0]['admin_password'];
    $admin_role = $result1[0]['admin_role'];

    $query2 = "SELECT * FROM quanly WHERE admin_role='moderator'";
    $result2 = executeSelectQuery($query2);

    ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Junior Achievement Singapore</title>

        <!--Embed CSS Scripts!-->
        <style type="text/css" title="currentStyle">
            @import "../media/css/dataTable.css";
            @import "../media/css/jquery-ui-1.8.13.custom.css";
            @import "../media/css/screen.css";
        </style>

        <!--Embed Javascripts-->
        <script type="text/javascript" src="../media/js/jquery/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery-ui-1.8.13.custom.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="../media/js/jquery/ajaxReloadDataTable.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery.dataTables.editable.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery.validate.js"></script>
        <script type="text/javascript" src="../media/js/jquery/jquery.jeditable.js"></script>


        <!--Onsite scripts-->
        <script type="text/javascript" charset="utf-8">

            $(document) .ready(function(){
                //Script to manage school events table
                $("#school_events_table").dataTable({"sPaginationType": "full_numbers"});
                $("#school_contac_table").dataTable({"sPaginationType": "full_numbers"});


            });


        </script>
    </head>
    <body>
        <!-- DON'T TOUCH! Start: page-top-outer -->
            <?php
            top_outer();
            ?>
        <!-- End: page-top-outer -->

        <div class="clear">&nbsp;</div>

        <!--  start nav-outer-repeat................................................................................................. START -->
        <div class="nav-outer-repeat">
            <!--  start nav-outer -->
            <div class="nav-outer">

                <!-- start nav-right -->
                    <?php
                    nav_right();
                    ?>
                <!-- end nav-right -->


                <!--  start nav -->
                <div class="nav">
                    <div class="table">

                            <?php
                            navigation();
                            ?>

                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                </div>
                <!--  start nav -->

            </div>
            <div class="clear"></div>
            <!--  start nav-outer -->
        </div>
        <!--  start nav-outer-repeat................................................... END -->

        <div class="clear"></div>

        <!-- start content-outer ........................................................................................................................START -->
        <div id="content-outer">
            <!-- start content -->
            <div id="content">

                <!--  start page-heading --> <!--lyedit-->
                <div id="page-heading">
                    <h1>Admin Account</h1>
                </div>
                <!-- end page-heading -->

                <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                    <tr>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                        <th class="topleft"></th>
                        <td id="tbl-border-top">&nbsp;</td>
                        <th class="topright"></th>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                    </tr>
                    <tr>
                        <td id="tbl-border-left"></td>
                        <td>
                            <!--  start content-table-inner ...................................................................... START -->
                            <div id="content-table-inner">
                                    <?php echo "<b><font color =red>$mes </font></b>" ?><br/><br/>
                                <h3>Dear Ms <?php echo $admin_name ?>. This is the page where you can edit your account information.</h3>
                                <!--  start table-content  -->
                                <div id="table-content">
                                    <div id="details_content">
                                        <!--  Can put table start from here within this div-->

                                        <form action="doEditAccount.php" method="post" id ="programform">
                                            <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                <input type="hidden" name="id" value=""></input>
                                                <tr>
                                                    <th valign="top">Admin name: </th>
                                                    <td>
                                                        <input type="text" name="admin_name" class="inp-form" value = '<?php echo $admin_name ?>'></input>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Admin Email: </th>
                                                    <td>
                                                        <input type="text" name="admin_email" class="inp-form" value = '<?php echo $admin_email ?>'></input>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Password: </th>
                                                    <td>
                                                        <input type="password" name="admin_password" class="inp-form" value = '__________'/>
                                                    </td>
                                                </tr>
                                            </table>
                                            <table>
                                                <tr>
                                                <td><input type="button" value="" class="form-back" onClick="javascript:history.go(-1)"/></td>
                                                <td><input type="submit" value="" class="form-save" /></td>
                                                    <?php
                                                    if($admin_role=="admin") {
                                                        ?>
                                                <td><input type="button" value="" onclick="window.location.replace('newAdmin.php')" class="add-admin"/></td>
                                                        <?php
                                                    }
                                                    ?>
                                                </tr>
                                            </table>
                                        </form>


                                        <!--End of #school_details!-->
                                        <br/>
                                            <?php
                                            if($admin_role=="admin" && $result2!=0 ) {
                                                ?>
                                        <h3>Dear Ms <?php echo $admin_name ?>. This is the list of Admin under you:</h3>
                                        <form name="delete_admin" method="post" action="adminDelete.php" id ="admin">
                                            <table cellpadding="0" cellspacing="0" border="0" class="display" id="school_events_table">
                                                <thead>
                                                    <tr>
                                                        <th><input type="checkbox" onClick="toggle1(this)" /></th>
                                                        <th>Admin Name</th>
                                                        <th>Admin Email</th>
                                                        <th></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                            <?php
                                                            for ($i=0;$i<count($result2);$i++) {

                                                                $no = $i+1;
                                                                $id = $result2[$i]['admin_id'];
                                                                $name =$result2[$i]['admin_name'];
                                                                $email =$result2[$i]['admin_email'];


                                                                echo "<td><input type = 'checkbox' name ='id_admin[]' value =$id ></input></td>";
                                                                echo "<td>$name</td>";
                                                                echo "<td>$email</td>";
                                                                ?>
                                                    <td><a href='adminDelete.php?id= <?php echo $id?>' onclick="return  confirm('You sure you want to delete this admin?')">Delete</a></td>
                                                                <?php
                                                                echo "</tr>";
                                                            }
                                                            ?>
                                                </tbody>
                                            </table>
                                            <input type="submit" name="submit" value="" class="form-delete" onClick="if (confirm('Are you sure you want to delete?')) commentDelete(1); return false"/><br/>
                                        </form>
                                                <?php
                                            }
                                            ?>



                                    </div>
                                    <!--  end table-content here -->
                                </div>
                                <div class="clear"></div>
                            </div>
                            <!--  end content-table-inner ............................................END  -->
                        </td>
                        <td id="tbl-border-right"></td>
                    </tr>
                    <tr>
                        <th class="sized bottomleft"></th>
                        <td id="tbl-border-bottom">&nbsp;</td>
                        <th class="sized bottomright"></th>
                    </tr>
                </table>

                <div class="clear">&nbsp;</div>
            </div><!--  end content -->

            <div class="clear">&nbsp;</div>
        </div>
        <!--  end content-outer........................................................END -->
            <?php
            footer();
            ?>

    </body>
</html>

    <?php
}else {
    header("Location: ../include/login.html");
}
?>